package com.tsingtree.modular.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tsingtree.base.pojo.page.LayuiPageFactory;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.tsingtree.modular.entity.NanMessage;
import com.tsingtree.modular.mapper.NanMessageMapper;
import com.tsingtree.modular.model.params.NanMessageParam;
import com.tsingtree.modular.model.result.NanMessageResult;
import com.tsingtree.modular.service.NanMessageService;
import com.tsingtree.roses.core.util.ToolUtil;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;


/**
 * <p>
 * 站内信 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2024-07-08
 */
@Service
public class NanMessageServiceImpl extends ServiceImpl<NanMessageMapper, NanMessage> implements NanMessageService {

    @Override
    public void add(NanMessageParam param){
        NanMessage entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(NanMessageParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(NanMessageParam param){
        NanMessage oldEntity = getOldEntity(param);
        NanMessage newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public NanMessageResult findBySpec(NanMessageParam param){
        return null;
    }

    @Override
    public List<NanMessageResult> findListBySpec(NanMessageParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(NanMessageParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(NanMessageParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private NanMessage getOldEntity(NanMessageParam param) {
        return this.getById(getKey(param));
    }

    private NanMessage getEntity(NanMessageParam param) {
        NanMessage entity = new NanMessage();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
